<script>
import { reactive, toRefs } from "vue";
import { useRouter } from "vue-router";
import { Toast } from "vant";
export default {
  setup() {
    let router = useRouter();
    const resetpsw = reactive({
      password: "",
      restpass: "",
    });
    const submit = () => {
      let pass = /^[a-zA-Z0-9]\w{6,17}$/;
      if (!pass.test(resetpsw.restpass) || !pass.test(resetpsw.password)) {
        //不正确处理
        Toast("密码格式不正确,请重新输入");
        return;
      }

      if (resetpsw.password != resetpsw.restpass) {
        Toast("俩次输入的密码不同");
      } else {
        Toast("修改完成");
        router.push({ path: "/loginpsw" });
      }
    };
    return {
      ...toRefs(resetpsw),
      submit,
    };
  },
};
</script>

<template>
  <div class="container resetpsw">
    <!-- 顶部 -->
    <div class="top">
      <div class="left">
        <i class="iconfont icon-zuobian"></i>
        <a @click="$router.go(-1)">返回</a>
      </div>
      <div class="center">重置密码</div>
    </div>

    <!-- 重置密码 -->
    <div class="form">
      <div class="get">
        <input
          type="password"
          name="phone"
          placeholder="请输入新密码"
          v-model="password"
        />
      </div>
      <div class="get">
        <input
          type="password"
          name="phone"
          placeholder="请再次输入新密码"
          v-model="restpass"
        />
      </div>

      <p class="vakudate-tip">
        密码6-16位。可包含数字、字母（区分大小写）、非空格字符。
      </p>

      <p class="important">新密码不能为空</p>

      <button type="button" class="login" @click="submit">确定</button>
    </div>
  </div>
</template>

<style lang="scss" scoped>
/* 顶部 */
.resetpsw .top {
  height: 44px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  background: linear-gradient(270deg, #7b0b3b 0%, #d51c78 100%);
  color: #fff;
  padding-right: 10px;
  padding-left: 5px;
  .center {
    font-size: 19px;
    height: 44px;
    line-height: 44px;
    flex: 1;
    text-align: center;
    margin-right: 48px;
  }
  .left {
    display: flex;
    align-items: center;
    a {
      display: inline-block;
      font-size: 14px;
      color: #fff;
    }
    i {
      margin-right: 2px;
    }
  }
  .right {
    display: flex;
    align-items: center;
    a {
      display: inline-block;
      font-size: 14px;
      color: #fff;
    }
    i {
      margin-right: 4px;
    }
  }
}

/* 验证码 */
.resetpsw .form {
  padding-left: 20px;
  padding-right: 20px;
  input {
    &::placeholder {
      color: #c4c4c4;
      font-size: 16px;
    }
  }
  .login {
    width: 100%;
    font-size: 18px;
    color: #fff;
    text-align: center;
    background: linear-gradient(to right, #7b0b3b, #d51c78, #7b0b3b);
    border: none;
    margin-top: 20px;
    height: 40px;
    border-radius: 20px;
    letter-spacing: 3px;
  }
}
.resetpsw .phonenum,
.get {
  height: 55px;
  font-size: 16px;
  border-bottom: 1px solid #f5f5f5;
}
.resetpsw .phonenum {
  display: flex;
  justify-content: space-between;
  align-items: center;
  input {
    flex: 1;
    height: 55px;
    line-height: 55px;
    margin-top: 8px;
  }
}
.resetpsw .get {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  input {
    flex: 1;
    height: 55px;
    line-height: 55px;
    margin-top: 6px;
  }
  i {
    display: inline-block;
    width: 1px;
    height: 20px;
    background-color: #e6e6e6;
    margin-right: 17px;
  }
  span {
    color: #d51c78;
    margin-right: 18px;
  }
}
.resetpsw .vakudate-tip {
  color: #aaa;
  font-size: 12px;
  line-height: 20px;
  margin-top: 10px;
}
.resetpsw .important {
  color: #d51c78;
  font-size: 12px;
  margin-top: 10px;
}
</style>